<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/bootstrap-grid.min.css">
    <link rel="stylesheet" href="css/bootstrap-reboot.min.css">
</head>
<body>
<div class="container">
    <div class="row" style="margin-top: 20px;">
        <div class="col-12">
            <h2>
                Springboot + ES - 演示商品搜索
            </h2>
        </div>
    </div>

    <div class="row" style="margin-top: 20px;" id="app">
        <div class="col-9">
            <form class="form-inline">
                <div class="form-group mb-2">
                    <input type="text" class="form-control" id="title-mysql" placeholder="搜索你想要的" v-model="keyword">
                </div>
                <button type="button" class="btn btn-primary mb-2" style="margin-left: 5px;" v-on:click="searchWithEs">ES</button>
            </form>
            <div class="row" >
                <div class="col-sm-6" v-for="(good,index) in goods" style="margin-top: 20px;">
                    <div class="card">
                        <div class="card-img-top">
                            <img :src="'img/'+(index+1)+'.jpg'" style="height: auto;width: 100%"/>
                        </div>
                        <div class="card-body">
                            <h5 class="card-title">{{good.name}}</h5>
                            <p>{{good.describe}}</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="./js/vue.js"></script>
<script src="./js/axios.min.js"></script>
<script>

    var app ;
    app = new Vue({
        el:'#app',
        data:{
            goods:[],
            keyword:''
        },
        methods:{
            getGoods:function () {
                var that = this;
                axios.get("http://localhost:8080/goods",{}).then(function (response) {
                    that.goods = response.data;
                })
            },
            searchWithEs:function () {
                var that = this;
                var param = {"keyword":that.keyword};
                axios.post("http://localhost:8080/searchGoods",param).then(function (response) {
                    that.goods = response.data;
                })
            }
        },
        created:function () {
            this.getGoods();
        }
    })


</script>
</body>
</html>